from rest_framework.views import APIView
from rest_framework.response import Response
from rest_framework import mixins, generics
from rest_framework import viewsets
from django_filters.rest_framework import DjangoFilterBackend
from rest_framework import filters


from goods.models import Goods, GoodsCategory
from tutorial.goods.serializers import GoodsSerializer, CategorySerializer
from tutorial.goods.filters import GoodsFilter
class GoodsListViewSet(mixins.ListModelMixin,viewsets.GenericViewSet):
    """商品列表"""
    queryset = Goods.objects.all()
    filter_backends = [DjangoFilterBackend, filters.SearchFilter, filters.OrderingFilter]
    # filterset_fields = ['name', 'market_price']
    filterset_class = GoodsFilter
    search_fields = ['name']
    ordering_fields = ['name']
    serializer_class = GoodsSerializer

class CategoryListViewSet(mixins.ListModelMixin, viewsets.GenericViewSet, mixins.RetrieveModelMixin):
    """商品列表"""
    queryset = GoodsCategory.objects.filter(category_type = 1)
    serializer_class = CategorySerializer
    # authentication_classes = 